package be.djdb.Filefilter;

import java.io.File;
import java.io.FilenameFilter;
import java.util.prefs.Preferences;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
/**
* @author Lieven Roegiers
* @copyright 2011
* @from JAVA_mylibs
*/
public abstract class MYabstractFileFilter extends FileFilter implements FilenameFilter{
	private String description;
	private String ext;
	private String contenttype;
	/**
	 * 		Preferences userPrefs = Preferences.userRoot().node( "/com/mindprod/mypackage" );
		File suggestedFile = new File ( userPrefs.get( "SAVEDIR", "C:" ), saveName );
		JFileChooser fc = new JFileChooser();
		fc.setSelectedFile( suggestedFile );
		// filter out all but JPG files from view, you need
		// a javax.swing.filechooser.FileFilter
		// NOT a java.io.FilenameFilter;
		fc.addChoosableFileFilter(null);
		// In a simple case like this you could have used
		// javax.swing.filechooser.FileNameExtensionFilter
		// instead of rolling your own custom FileFilter.
		int result = fc.showSaveDialog(null);
		switch (result){
		   case JFileChooser.APPROVE_OPTION:
		      File file = fc.getSelectedFile();
		      // save using file.
		      // save same directory for next time.
		      // persisted in registry, directory last used
		      userPrefs.put( "SAVEDIR",  fc.getCurrentDirectory().getAbsolutePath() );
		      break;
		   case JFileChooser.CANCEL_OPTION:
		   case JFileChooser.ERROR_OPTION:
		      break;
		   default:
		   }

	 * */
	public MYabstractFileFilter(String ext,String description) {
		    this.ext = ext;
			this.description =description;
   }
	public MYabstractFileFilter(String ext,String description,String contenttype) {
	    this.ext = ext;
		this.description = description;
		this.contenttype = contenttype;
	}
   /**
    * Return true if this file should be shown in the directory pane,
    * @see FileFilter#accepts
    */
   public boolean accept( File f ){
      return f != null && f.isDirectory()||f.getName().toLowerCase().endsWith(ext);
   }
   public String getcontenttype(){
   		return contenttype;
   }
   /**
   * Returns the human readable description of this filter.
   * @see setDescription
   * @see FileFilter#getDescription
   */
   public String getDescription(){return description;}
}
